package com.syh.jn.scm.domain.supplier.entity.purchase;

import cn.redscarf.commons.util.bean.ExtBeanUtils;
import com.syh.core.ddd.domain.AbstractSimpleAggregate;
import com.syh.core.ddd.domain.AbstractSimpleEntityObject;
import com.syh.jn.scm.dto.supplier.purchase.PurchaseGoodsDto;
import com.syh.jn.scm.dto.supplier.purchase.PurchaseOrderMto;
import com.syh.jn.scm.dto.supplier.purchase.PurchaseOrderSto;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.UUID;

/**
 * 采购单项实体
 */
@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class PurchaseOrderItem extends AbstractSimpleAggregate<Long> {
  //添加明细
  protected PurchaseOrderItem(PurchaseOrderSto.PurchaseOrderItemSTO itemSto) {
    ExtBeanUtils.copyProperties(itemSto, this, false);
    this.uuid = UUID.randomUUID().toString();
    //物流相关数量记录初始为0
    this.generatedQuantity = BigDecimal.ZERO;
    this.outedQuantity = BigDecimal.ZERO;
    this.inQuantity = BigDecimal.ZERO;
    this.totalAmount = this.price.multiply(this.quantity).setScale(2,RoundingMode.HALF_UP);//商品总额
  }

  //修改明细
  protected PurchaseOrderItem(PurchaseOrderMto.PurchaseOrderItemMTO itemMto) {
    ExtBeanUtils.copyProperties(itemMto, this, false);
    //物流相关数量记录初始为0
    this.generatedQuantity = BigDecimal.ZERO;
    this.outedQuantity = BigDecimal.ZERO;
    this.inQuantity = BigDecimal.ZERO;
    this.uuid = UUID.randomUUID().toString();
    this.totalAmount = this.price.multiply(this.quantity).setScale(2,RoundingMode.HALF_UP);//商品总额
  }

  //确认收货
  protected BigDecimal calculateTotalInAmount() {
    this.inTotalAmount = this.price.multiply(this.inQuantity).setScale(2,RoundingMode.HALF_UP);//商品收货总额
    return this.inTotalAmount;
  }
  /**
   * 销售订单项id
   */
  private Long saleOrderItemId;
  /**
   * 归属id
   */
  private Long businessEntityId;
  /**
   * 采购订单id
   */
  private Long purchaseOrderId;
  /**
   * 商品id
   */
  private Long goodsId;
  /**
   * 商品名称
   */
  private String goodsName;
  /**
   * 分类id
   */
  private Long categoryId;
  /**
   * 品牌id
   */
  private Long goodsBrandId;
  /**
   * 品牌名称
   */
  private String goodsBrandName;
  /**
   * 商品编码
   */
  private String goodsCode;
  /**
   * 所属种类,应用分类的父类目录
   */
  private String categoryCatalogCode;
  /**
   * -1 辅助商品  1  基础商品
   */
  private Short isDefaultGoods;
  /**
   * 与基础商品转换率（如果是基础商品 则等于1）
   */
  private BigDecimal conversionRate;
  /**
   * 所属种类名称
   */
  private String categoryName;
  /**
   * 单位
   */
  private String units;
  /**
   * 条码
   */
  private String codeBar;
  /**
   * 规格
   */
  private String specName;
  /**
   * 单价
   */
  private BigDecimal price;
  /**
   * 商品采购数量
   */
  private BigDecimal quantity;
  /**
   * 物流单生成数量
   */
  private BigDecimal generatedQuantity;
  /**
   * 采购退货生成数量
   */
  private BigDecimal generatedReturnQuantity;
  /**
   * 已出库数量(发货)
   */
  private BigDecimal outedQuantity;
  /**
   * 商品发货数量
   */
  private BigDecimal deliveryQuantity;
  /**
   * 商品发货总额
   */
  private BigDecimal deliveryTotalAmount;
  /**
   * 商品实际毛重
   */
  private BigDecimal roughWeight;
  /**
   * 商品实际净重
   */
  private BigDecimal netWeight;
  /**
   * 商品总额
   */
  private BigDecimal totalAmount;
  /**
   * 采购入库(收货)数量
   */
  private BigDecimal inQuantity;
  /**
   * 商品采购入库(收货)总额
   */
  private BigDecimal inTotalAmount;
  /**
   * 备注
   */
  private String remark;
  /**
   * 字典id
   */
  private Long dictionaryId;
}
